<template>
	<view class="orderInformation_container">
		<view class="" style="height: 160rpx;">
			<view class="mail_List fixed z_ninetynine">
				<view class="mail" style="font-weight: 700;">
					<view class="order" v-if="current==1">工单信息</view>
					<view class="order" v-if="current==2">转交工单</view>
				</view>
			</view>
			<view class="icon fixed z_ninetynine">
				<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
			</view>

		</view>
		<!-- 报事人信息 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事人信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="报事人:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.reportPerson" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="联系方式:">
					<view class="" style="display: flex;justify-content: flex-end;">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							:placeholder="particulars.phoneNumber" :clearable="false" :disabled="true" />
						<u-rate :count="count" :min-count="1" v-model="value" @change="change"></u-rate>
					</view>
				</u-form-item>
			</u-form>
		</view>
		<!-- 报事详情 -->
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事详情</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="标题:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.describe" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="类型:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="建议"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="报事时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.createTime" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件地址:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.addressCommunity" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件描述:" label-position="top">
					<u-input v-model="form.describe" type="textarea"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.describe" :clearable="false" :disabled="true" />
				</u-form-item>
				<!-- <u-form-item>
					<view style="display: flex; justify-content: space-around;">
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
					</view>
				</u-form-item> -->
				
				<u-form-item v-show="imagesVos.length!=0">
					<view style="display: flex; flex-wrap: wrap;">
						<view style="width:210rpx; height: 316rpx;margin-right: 10rpx;margin-bottom: 10rpx; background-color: #f2f2f2;" v-for="(item,index) in imagesVos">
							<image :src="item.imgUrl" mode="" style="width: 100%;height: 100%;"></image>
						</view>
					</view>
				</u-form-item>
				
			</u-form>
		</view>
		<!-- 工单分配 -->
		<view class="order_Allocation">
			<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
					style="font-weight: 700; font-size: 30rpx;" v-if="current==1">工单分配</text>
				<text style="font-weight: 700; font-size: 30rpx;" v-if="current==2">工单分配1</text>
			</view>
			<view class="card" style="position: relative; padding: 0 42rpx;">
				<u-form :model="form" ref="uForm">
					<!-- 					<u-form-item label="选择负责人:">
						<u-input v-model="form.Reporter"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="刘备"
							:clearable="false" :disabled="true" />
					</u-form-item> -->
					<u-form-item label="执行人:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							:placeholder="particulars.staffName" :clearable="false" :disabled="true" />
					</u-form-item>
					<!-- 					<u-form-item label="维保时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 12: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="结束时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 24: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item> -->
					<u-form-item label="执行状态:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							:placeholder="particulars.executeStatus=='0'? '未执行' : particulars.executeStatus=='1' ? '完成' : '未完成'"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<image src="/static/workOrder/Group689.png" v-if="current==1" mode=""
						style=" position: absolute;top: 94rpx; left: 236rpx; width: 280rpx; height: 280rpx;">
					</image>
					<image src="/static/workOrder/Group804.png" v-if="current==2" mode=""
						style=" position: absolute;top: 94rpx; left: 236rpx; width: 280rpx; height: 280rpx;">
					</image>
				</u-form>
			</view>
		</view>
		<!-- 工单分配 -->
		<view class="order_Allocation" v-if="current==2">
			<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text <text
					style="font-weight: 700; font-size: 30rpx;">工单分配2</text>
			</view>
			<view class="card" style="padding: 0 42rpx;">
				<u-form :model="form" ref="uForm">
					<!-- <u-form-item label="选择负责人:">
						<u-input v-model="form.Reporter"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="孙权"
							:clearable="false" :disabled="true" />
					</u-form-item> -->
					<u-form-item label="选择执行人:">
						<!-- 						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="周瑜、陆逊"
							:clearable="false" :disabled="true" /> -->
						<u-input v-model="form.title" :custom-style="{'font-weight': '600'}" :disabled="true"
							:type="newList==''? 'select' : 'text'" :select-open="show"
							placeholder-style="color: #cccccc; text-align: right;"
							:placeholder="newList==''? '请选择执行人' : newList" @click="show = true" />
					</u-form-item>
					<!-- 					<u-form-item label="维保时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 12: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="结束时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 24: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item> -->
				</u-form>
				<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
			</view>
		</view>
		<view class="button" v-if="current==1">
			<u-button type="primary" style="flex: 1;" @click="resolved">提醒</u-button>
			<u-button type="success" style="flex: 1;" @click="Approved">转交</u-button>
		</view>
		<view class="button" v-if="current==2">
			<u-button type="primary" style="flex: 1;" @click="cancel">取消</u-button>
			<u-button type="success" style="flex: 1;" @click="determine">确定</u-button>
		</view>
		<u-popup v-model="show3" mode="center" width="626rpx" height="430rpx" border-radius="20">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				工单提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">催促工单成功！</view>
			</view>
		</u-popup>
		<u-popup v-model="show2" mode="center" width="626rpx" height="430rpx" border-radius="20">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				工单提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">工单发布成功</view>
			</view>
		</u-popup>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// form表单
				form: {
					Reporter: '',
					title: '',
					address: '',
					describe: '',
					chargePerson: '',
					Executor: '',
					Maintenance: '',
					end: '',
					// 手机号码
					staffPhone: ''
				},
				// 演示地址，请勿直接使用
				action: 'http://www.example.com/upload',
				button_flag: true,
				buttontwo_flag: false,
				current: 1,
				show: false,
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				show3: false,
				show2: false,
				newList: '',
				// 待接单Id
				orderId: '',
				// 工单信息
				particulars: '',
				imagesVos:'',
				// 审核通过
				staff: '',
				count: 1,
				value: 0,
				userPhone: '',
				userName: ''
			}
		},
		onLoad(val) {
			this.loginId = uni.getStorageSync("setModel")
			if (val.orderId) {
				this.orderId = val.orderId
				// 待接单详情
				this.getListVehicleByIds()
			}
		},
		methods: {
			// 收藏电话号码
			change(e) {
				console.log(e)
				this.$http.post('Collect/insertOwnerTenant', {
					userPhone: this.userPhone,
					userId: this.loginId.userId,
					userName: this.userName
				}).then(res => {
					console.log(res, '收藏电话号码')
					// this.particulars=res.data
				})
			},
			// 待接单详情
			getListVehicleByIds() {
				this.$http.get('WorkOrder/OrderDetails', {
					orderId: this.orderId,
					loginId: this.loginId.userId
				}).then(res => {
					console.log(res, '待接单详情')
					this.particulars = res.data
					this.imagesVos=res.data.imagesVos
					this.userPhone = res.data.phoneNumber
					this.userName = res.data.reportPerson
				})
			},
			resolved() {
				this.show = true
			},
			// 点击转交按钮
			Approved() {
				// this.form.title=this.particulars.staffName
				this.current = 2
				this.$http.get('WorkOrder/getStaff', {
					deptId: this.loginId.deptId,
					orderId: this.orderId
				}).then(res => {
					console.log(res, '执行人')
					// this.particulars=res.data
					let lists = res.data
					this.list = this.changeKey(lists, ['value', 'label', 'staffPhone']);
				})
			},
			// 注意返回值为一个数组，单列时取数组的第一个元素即可(只有一个元素)
			confirm(e) {
				// console.log(e);
				let sign = ''
				e.forEach((item, index) => {
					this.sign = item.value
					this.form.title = item.label
					// console.log(item.label);
					// console.log(this.sign);
				})
				this.list.forEach((item, index) => {
					if (item.value == this.sign) {
						console.log(item.staffPhone)
						this.form.staffPhone = item.staffPhone
					}
				})
				// console.log(e-'1')
				// let abc = this.list[e-'1'].staffPhone
				// console.log(abc)
			},
			cancel() {
				this.current = 1
			},
			// 点击确定
			determine() {
				// this.show2 = true
				// console.log(171)
				
				if(this.form.title=='') {
					this.$refs.uToast.show({
						title: '请选择执行人',
					})
				} else {
					this.$http.put('WorkOrder/updateWordOrder', {
						phone: this.form.staffPhone,
						orderId: this.orderId
					}).then(res => {
						console.log(res, '工单转交')
						// this.particulars=res.data
					})
					setTimeout(function() {
						uni.navigateBack()
					}, 1000);
				}
			},
			changeKey(lists, key) {
				let newArr = [];
				lists.forEach((item) => {
					let newObj = {};
					for (var i = 0; i < key.length; i++) {
						newObj[key[i]] = item[Object.keys(item)[i]]
					}
					newArr.push(newObj);
				})
				return newArr;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.orderInformation_container {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;

			.mail {
				padding: 10rpx 0;
				// margin-top: 96rpx;
				color: #999999;
				font-size: 40rpx;
				background-color: #e5e5e5;
			}

			.order {
				text-align: center;
			}
		}

		/deep/.card {
			.u-form-item--left {
				flex: unset !important;
				width: unset !important;
			}
		}

		.order_Allocation {
			/deep/.card {
				u-form-item {
					.u-input {
						input {
							text-align: right !important;
						}

					}
				}
			}
		}

		.icon {
			position: absolute;
			top: 18rpx;
			// top: 114rpx;
			left: 20rpx;
		}

		.second_card {
			.u-cell {
				padding: 18rpx 32rpx;

				/deep/.u-cell__value {
					color: #333333;
					font-weight: 600;
				}
			}

			/deep/.uni-card__content {
				padding: 16rpx 24rpx;
			}
		}

		/deep/button {
			border-radius: unset !important;
		}

		.uni-border[data-v-19622063]:after {
			border: unset;
		}

		/deep/.uni-border.data-v-19622063:after {
			border: unset;
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}

		.button {
			display: flex;
			// position: fixed;
			// left: 0;
			// right: 0;
			// bottom: 0;
			margin-top: 200rpx;
			border-radius: 14rpx;
			overflow: hidden;
			z-index: 9;

			.u-btn {
				border-radius: unset;
			}
		}

		.work_Order {
			margin-top: 60rpx;
			text-align: center;

			.work_Order_top {
				width: 168rpx;
				height: 168rpx;
				margin: 0 auto;
				background-color: #e5e5e5;
				border-radius: 50%;
			}
		}
	}
</style>
